#!/bin/sh
patch -p0 < $0
exit 0
Index: compiler/lib/AsmParser/LLParser.cpp
===================================================================
--- compiler/lib/AsmParser/LLParser.cpp	(LLVM 3.5)
+++ compiler/lib/AsmParser/LLParser.cpp	(cppamp-driver-ng-35)
@@ -3971,7 +3971,7 @@
       ParseType(DestTy))
     return true;
 
-  if (!CastInst::castIsValid((Instruction::CastOps)Opc, Op, DestTy)) {
+  if (!CastInst::castIsValid((Instruction::CastOps)Opc, Op, DestTy, false)) {
     CastInst::castIsValid((Instruction::CastOps)Opc, Op, DestTy);
     return Error(Loc, "invalid cast opcode for cast from '" +
                  getTypeString(Op->getType()) + "' to '" +
Index: compiler/lib/IR/Instructions.cpp
===================================================================
--- compiler/lib/IR/Instructions.cpp	(LLVM 3.5)
+++ compiler/lib/IR/Instructions.cpp	(cppamp-driver-ng-35)
@@ -2793,7 +2793,8 @@
 /// it in one place and to eliminate the redundant code for getting the sizes
 /// of the types involved.
 bool 
-CastInst::castIsValid(Instruction::CastOps op, Value *S, Type *DstTy) {
+CastInst::castIsValid(
+  Instruction::CastOps op, Value *S, Type *DstTy, bool AddrSpaceCastSupport) {
 
   // Check for type sanity on the arguments
   Type *SrcTy = S->getType();
@@ -2874,9 +2875,11 @@
     if (!SrcPtrTy)
       return SrcTy->getPrimitiveSizeInBits() == DstTy->getPrimitiveSizeInBits();
 
-    // If both are pointers then the address spaces must match.
-    if (SrcPtrTy->getAddressSpace() != DstPtrTy->getAddressSpace())
-      return false;
+    if (AddrSpaceCastSupport) {
+      // If both are pointers then the address spaces must match.
+      if (SrcPtrTy->getAddressSpace() != DstPtrTy->getAddressSpace())
+        return false;
+    }
 
     // A vector of pointers must have the same number of elements.
     if (VectorType *SrcVecTy = dyn_cast<VectorType>(SrcTy)) {
Index: compiler/include/llvm/IR/InstrTypes.h
===================================================================
--- compiler/include/llvm/IR/InstrTypes.h	(LLVM 3.5)
+++ compiler/include/llvm/IR/InstrTypes.h	(cppamp-driver-ng-35)
@@ -634,7 +634,8 @@
   /// Opcode op is valid or not.
   /// @returns true iff the proposed cast is valid.
   /// @brief Determine if a cast is valid without creating one.
-  static bool castIsValid(Instruction::CastOps op, Value *S, Type *DstTy);
+  static bool castIsValid(Instruction::CastOps op, Value *S, Type *DstTy,
+                          bool AddrSpaceCastSupport = true);
 
   /// @brief Methods for support type inquiry through isa, cast, and dyn_cast:
   static inline bool classof(const Instruction *I) {
